<?php

/**
 * 用户反馈页面
 */

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
/* require(ROOT_PATH . 'includes/lib_order.php');

// 载入语言文件
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/user.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/shopping_flow.php'); */

/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */

assign_template();
assign_dynamic('flow');
$position = assign_ur_here(0, $_LANG['shopping_flow']);
$smarty->assign('page_title',       $position['title']);    // 页面标题
$smarty->assign('ur_here',          $position['ur_here']);  // 当前位置

$smarty->assign('categories',       get_categories_tree()); // 分类树
$smarty->assign('helps',            get_shop_help());       // 网店帮助
$smarty->assign('lang',             $_LANG);
/*
$smarty->assign('show_marketprice', $_CFG['show_marketprice']);
$smarty->assign('data_dir',    DATA_DIR);       // 数据目录 */

// 提交留言 
if ($_REQUEST['act'] != 'submit'){
	
/* 	$result['cart_goods_list'] = $smarty->fetch('library/cart.lbi');
	
	$json  = new JSON;
	//var_dump($result);
	die($json->encode($result)); */
	
	$smarty->display('Complaint_feedback.dwt');
}else{
		
	$code = !empty($_POST['code']) ? compile_str(trim($_POST['code'])) : '';
	include_once('includes/cls_captcha.php');
	$validator = new captcha();
	$validator->session_word = 'captcha_login';	
	
	$email = isset($_POST['email'])   ? compile_str(trim($_POST['email']))    : '';
	$feedback = isset($_POST['feedback'])   ? compile_str(trim($_POST['feedback']))  : '';
	
	if($validator->check_word($_POST['code'])){
		$user_id = !empty($_SESSION['user_id']) ? $_SESSION['user_id'] : '0';
		$user_id = compile_str($user_id);
		
		// 如果用户id非空，则去数据库取用户名
		if($user_id !='0' && ( strlen($user_id)< 10) ){
			$sql = "SELECT user_name FROM ".$GLOBALS['ecs']->table('users')
					." WHERE user_id = '".$user_id."'";
			$user_name = $GLOBALS['db']->getOne($sql);
		}
		// 用户名空，则标记为匿名用户
		if( is_null($user_name) or $user_name=='0' ) $user_name = '匿名';	
		
		//$post_time = date("Y-m-d H:i:s",time());
		
		date_default_timezone_set("Asia/Shanghai");
		$post_time = date("Y-m-d H:i:s");
		
		$sql="insert into".$GLOBALS['ecs']->table('feedback')."(user_id,user_name ,user_email,msg_content,msg_time)".
				"values ('$user_id','$user_name','$email','$feedback','$post_time')";
		mysql_query($sql);		
		echo "success";
	}else{
		echo "error";
	}
	
}


?>